package team.seekers.catering.order.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.seekers.catering.common.result.R;
import team.seekers.catering.common.result.ResultCode;
import team.seekers.catering.common.utils.CateringUtil;
import team.seekers.catering.food.service.ComboService;
import team.seekers.catering.food.service.FoodService;
import team.seekers.catering.order.entity.dto.add.OrderAddDTO;
import team.seekers.catering.order.entity.vo.info.OrderInfoVO;
import team.seekers.catering.order.entity.vo.list.OrderListVO;
import team.seekers.catering.order.entity.vo.list.OrderTimeListVO;
import team.seekers.catering.order.service.OrderService;

import java.text.ParseException;
import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author hbc
 * @since 2022-02-28
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private ComboService comboService;

    /**
     * 根据当前时间
     * 查看当前时间段和下一时间段的订单信息
     * @return
     * @throws ParseException
     */
    @GetMapping("/orderForTime")
    public R orderForTime() throws ParseException {
        List<OrderTimeListVO> orderTimeListVOS = orderService.nowOrders();
        return R.success().data("rows",orderTimeListVOS);
    }

    /**
     * 查看所有时间段的订单信息
     * @return
     */
    @GetMapping("/allTimeOrders")
    public R allTimeOrders() {
        List<OrderTimeListVO> orderTimeListVOS = orderService.allTimeOrders();
        return R.success().data("rows",orderTimeListVOS);
    }

    /**
     * 厨师完成订单
     */
    @GetMapping("/end/{orderId}")
    public R end(@PathVariable("orderId") String orderId){
        if(!orderService.isExist(orderId)){
            return R.fail(ResultCode.GET_FAIL).message("订单不存在，请联系客服");
        }
        orderService.end(orderId);
        return R.success();
    }

    /**
     * 厨师端查询今日未完成订单
     */
    @GetMapping("/todayOrders")
    public R todayOrders(){
        List<OrderListVO> list = orderService.getTodayOrders();
        return R.success().data("rows",list);
    }

    /**
     * 厨师端查询今日已完成订单
     */
    @GetMapping("/todayEndOrders")
    public R todayEndOrders(){
        List<OrderListVO> list = orderService.getTodayEndOrders();
        return R.success().data("rows",list);
    }


}

